"""
   This is the abstract UI class. It should not be used except by its
   subclasses.
"""
import sys
import os
import thread
from network import EntangledNetworkLayer
from listen import Listener
import socket
import time

class AbstractUI:
   #don't worry about myPort not being set to DEFAULT_PORT, it gets overwritten anyway
   myPort = 1337
   listenPort = 1338
   connectIP = ""
   connectPort = -1
   nl = None
   shareDirs = None

   def searchResult(self, result):
      raise NotImplementedError

   def filePublished(self, result):
      raise NotImplementedError

   def download(self, result):
      raise NotImplementedError

   def __publishAllInDirs__(self, directories, network):
      for i in directories:
         i = os.path.expanduser(i)
         for entries in os.walk(i):
            for filename in entries[2]:
               network.share(os.path.join(entries[0], filename))

   def __init__(self, myPort, ip, port, shareDirs):
      print socket.gethostname()
      self.myPort = myPort
      self.listenPort = myPort + 1
      self.connectIP = ip
      self.connectPort = port
      self.shareDirs = shareDirs

      #listener = Listener(myPort)
      #thread.start_new_thread(listener.run, ())

      self.nl = EntangledNetworkLayer(self, self.myPort, self.listenPort, self.connectIP, self.connectPort)

